import Vue from 'vue'
import Vuex from 'vuex'

import {
	runGetUserInfo
} from '@/module/api'
import { getToken, saveToken } from '@/common/util'

Vue.use(Vuex)

const store = new Vuex.Store({
	state: {
		documentTitle: '',
		mobile: '',
		// userInfo: {
		// 	code: "asdfas",
		// 	create_time: "1970-01-01",
		// 	head: "https://wx.qlogo.cn/mmopen/vi_32/ymj2Grr595KBib9BKgRX6sERG06j1Ep7WwMea6eqZImiaNQCnYEyto7Yqu5svj1D6lPLfRkXDFNw73hL34LuFiayw/132",
		// 	id: 1,
		// 	level_id: 1,
		// 	nickname: "技术员",
		// 	username: "13074211161",
		// },
		userInfo: null,
		wxUserInfo: {},
		shareAppMessage: {
			title: '京商盟',
			path: '/pages/index/index'
		},
		windowWidth: 0,
		invite: ""
    },
	mutations: {
		updateMobile (state, mobile) {
			state.mobile = mobile
		},
		updateUserInfo (state, userInfo) {
			state.userInfo = userInfo
		},
		updateWxUserInfo (state, wxUserInfo) {
			state.wxUserInfo = wxUserInfo
		},
		updateDocumentTitle (state, documentTitle) {
			state.documentTitle = documentTitle
		},
		updateWindowWidth (state, windowWidth) {
			state.windowWidth = windowWidth
		},
		updateInvite (state, invite) {
			state.invite = invite
		}
	},
	actions: {
		async updateWindowWidth ({ commit }, windowWidth) {
			uni.getSystemInfo({
				success: (res) => {
					commit('updateWindowWidth', res.windowWidth)
				}
			})
		},
		async updateMobile ({ commit }, mobile) {
		    commit('updateMobile', mobile)
		},
		async updateUserInfo ({ commit }, userInfo) {
			commit('updateUserInfo', userInfo)
		},
		async updateWxUserInfo ({ commit }, wxUserInfo) {
			commit('updateWxUserInfo', wxUserInfo)
		},
		async updateInvite ({ commit }, invite) {
			commit('updateInvite', invite)
		},
		async updateDocumentTitle ({ commit }, documentTitle) {
			commit('updateDocumentTitle', documentTitle)
			// #ifdef H5
			document.title = documentTitle
			// #endif
		}
	}
})

export default store
